class Solution {
public:
    double myPow(double x, int n)
    {
        return n > 0 ? dfs(x, n) : (1.0 / dfs(x, n));
    }
    double dfs(double x, int n)
    {
        if (n == 0) return 1.0;

        double temp = dfs(x, n / 2);
        return n % 2 == 0 ? temp * temp : temp * temp * x;
    }
};